def get_form_errors(i_form):
    """
    获取表单验证的错误信息
    YPN 2021-09-21 Create
    :param i_form:
    :param i_model:
    :return: 使用换行符连接的字符串（一行一个错误信息）
    """
    # print(i_form.errors.as_ul())
    # print(i_form.errors.as_json())
    # print(i_form.errors.as_data())
    msg = []
    for error_field in i_form.errors:
        v_label = None
        for field in i_form.base_fields:
            if field == error_field:
                if field == 'username':
                    v_label = '用户名'
                elif field == 'email':
                    v_label = '邮箱'
                else:
                    v_label = i_form.base_fields[field].label
                break
        if v_label is None:
            v_label = i_form.errors[error_field].data[0].message
        else:
            if i_form.errors[error_field].data[0].code == 'required':
                v_label += '不能为空'
            elif i_form.errors[error_field].data[0].code == 'invalid':
                v_label += '格式错误'
            elif i_form.errors[error_field].data[0].code == 'max_length':
                v_label += '长度过长'
            elif i_form.errors[error_field].data[0].code == 'unique':
                v_label += '已存在'
            elif i_form.errors[error_field].data[0].code == 'invalid_choice':
                v_label += '选择无效'
            else:
                v_label += i_form.errors[error_field].data[0].message
        msg.append(v_label)

    if len(msg) == 0:
        msg.append(i_form.errors.as_json())
    return '</br>'.join('%s' % m for m in msg)
